#pragma once

#include "vrdatacore_global.h"
#include "transformable.h" 
#include <osg\Vec4>
#include "remarkactorbase.h"
#include <osg\ShapeDrawable>
#include <osg\PositionAttitudeTransform>
#include <osgManipulator\TranslateAxisDragger>
#include <osg\NodeCallback>

namespace osg
{
	template<class T> class ref_ptr;
	class Node;
	class Geode;
	class Material;
	class Geometry;
}

namespace CoreBase
{
	class Map;
}

namespace VrDataCore
{
	class VRDATACORE_EXPORT ControlPointActor:public RemarkActorBase
	{
	public:
		ControlPointActor(void);
		virtual void buildPropertyMap(){}
		bool isChanged();
	protected:
		virtual ~ControlPointActor(void);
		virtual void createDrawable();
		virtual void initialNode();
		osg::ref_ptr<osg::Box>							_pBox;
		osg::ref_ptr<osg::ShapeDrawable>				_shapeDrawable;
		osg::ref_ptr<osg::Geode>						_geode;
		osg::ref_ptr<osg::PositionAttitudeTransform>	_transformNode;
		osg::Vec3										_size;
		osg::Vec3										_preTranslation;
	};

	class VRDATACORE_EXPORT LineDrawable:public CoreBase::Transformable
	{
	public:
		LineDrawable(CoreBase::ActorBase* owneractor,QString name = "LineDrawable");
		void setLinePoint(QList<osg::Vec3> vec);
		void setLineColor(const osg::Vec4& mvec);
		virtual bool addChild(Drawable* child);
		virtual void removeChild(Drawable* child);
	protected:
		virtual ~LineDrawable(void);
		osg::ref_ptr<osg::Geometry>								_geometry;
		osg::ref_ptr<osg::Geode>								_geode;
		osg::ref_ptr<osg::Group>								_group;
		osg::ref_ptr<osg::Vec3Array>							_pointArray;
		osg::ref_ptr<osg::Vec4Array>							_arrayLineColor;
		osg::StateSet*											_publicStateSet;
	};

	class VRDATACORE_EXPORT LineActor:public DrawableActor
	{
	public:
		LineActor();
		void setLinePointList(QList<osg::Vec3f> pointlist);
		QList<osg::Vec3f> getLinePointList();
		QList<osg::Vec3f> getABSLinePointList();
		void setLineColor(osg::Vec4 mvec);
		osg::Vec4 getLineColor();
		virtual void onMapLoadBegin(CoreBase::Map*){}
		virtual void onMapLoadEnd(CoreBase::Map*);
		virtual void buildPropertyMap();
		void addControlPoint(const osg::Vec3& point);
		void removeControlPoint(CoreBase::ActorBase* controlpointactor);
		void showControlPoint(bool show);
		void showDragger(CoreBase::ActorBase* controlpointactor);
		void hideDragger();
		void update();
		virtual void setTraverseMask(unsigned int mask);
	protected:
		virtual ~LineActor(void);
		virtual void createDrawable();
		void editControlPoint(const osg::Vec3& oldpoint,const osg::Vec3& newpoint);
		osg::Vec4													_lineColor;
		QList<osg::Vec3f>											_pointList;
		QVector<osg::ref_ptr<ControlPointActor>>					_controlPointActorVector;
		osg::ref_ptr<osgManipulator::TranslateAxisDragger>			_dragger;
		bool														_showControlPoint;
		osg::MatrixTransform*										_preTransForm;
	};

	class LineActorUpdateCallback:public osg::NodeCallback
	{
		public:
		LineActorUpdateCallback(LineActor* la)
		{
			_la = la;
		}
		~LineActorUpdateCallback(){} ;
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
		{
			if( !_la )
				return ;
			_la->update();
		}
	protected:
		LineActor*				_la ;
	};
}